package operation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation  implements IOPeration {
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner in = new Scanner(System.in);
        System.out.println("请输入借阅图书的名称");
        String name = in.nextLine();
        boolean flag = true;//默认表示未找到这本书
        for (int i = 0; i < bookList.getUseSize(); i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(bookList.getBook(i).isBorrowed()) {
                    flag = false;
                    continue;
                }
                bookList.getBook(i).setBorrowed(true);
                System.out.println("成功接到此书，记得及时归还");
                return;
            }
        }
        if(flag){
            System.out.println("未找到这一本书，请重新核对一下书的名称");
        } else {
            System.out.println("不好意思，此书已经借完了");
        }
    }
}